package olegroshka.src.com.bofa.olegroshka.analitics;

import java.math.BigDecimal;

public class DiscountLevelDescriptor {
	private final BigDecimal min;
	private final BigDecimal max;
	private final BigDecimal rate;
	private final BigDecimal cumulativeDiscountValue;

	public DiscountLevelDescriptor(String min, String max, String rate,
			String cumulativeDiscountValue) {
		this.min = new BigDecimal(min);
		this.max = new BigDecimal(max);
		this.rate = new BigDecimal(rate);
		this.cumulativeDiscountValue = new BigDecimal(cumulativeDiscountValue);
	}

	public DiscountLevelDescriptor(BigDecimal min, BigDecimal max,
			BigDecimal rate, BigDecimal cumulativeDiscountValue) {
		this.min = min;
		this.max = max;
		this.rate = rate;
		this.cumulativeDiscountValue = cumulativeDiscountValue;
	}

	public BigDecimal getMin() {
		return min;
	}

	public BigDecimal getMax() {
		return max;
	}

	public BigDecimal getRate() {
		return rate;
	}

	public BigDecimal getCumulativeDiscountValue() {
		return cumulativeDiscountValue;
	}
	
	public BigDecimal getDiscount() {
		return max.add(min.negate()).multiply(rate);	
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((max == null) ? 0 : max.hashCode());
		result = prime * result + ((min == null) ? 0 : min.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		DiscountLevelDescriptor other = (DiscountLevelDescriptor) obj;
		if (max == null) {
			if (other.max != null)
				return false;
		} else if (!max.equals(other.max))
			return false;
		if (min == null) {
			if (other.min != null)
				return false;
		} else if (!min.equals(other.min))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "DiscountLevelDescriptor [min=" + min + ", max=" + max
				+ ", rate=" + rate + ", cumulativeDiscountValue="
				+ cumulativeDiscountValue + "]";
	}

}
